package com.group10.controller;

import com.group10.entity.Result;
import com.group10.service.FileService;
import com.group10.service.impl.FileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/files")
@CrossOrigin(origins = "*")
public class FileController {

    @Autowired
    private FileServiceImpl fileService;

    @PostMapping("/uploadFile")
    public Result<?> uploadFile(MultipartFile file) throws IOException {
        System.out.println("-----------上传");
        String url = fileService.uploadFile(file);
        return Result.success(url);
    }

    /**
     * 用户信息获取
     * @param flag 文件url
     */
    @GetMapping("/{flag}")
    public void getFiles(@PathVariable String flag, HttpServletResponse response){
        fileService.getFile(flag,response);
    }

    @PutMapping("/deleteFile")
    public void DeleteFile(String url){
        fileService.deleteFile(url);
    }
}
